package routes

import (
	"github.com/goravel/framework/contracts/route"
	"github.com/goravel/framework/facades"
	"goravel/app/http/controllers"
	"goravel/app/http/controllers/attachment"
	"goravel/app/http/controllers/system"
	"goravel/app/http/controllers/user"
	. "goravel/app/http/middleware"
)

func Api() {
	dk_ctrl := controllers.NewDeepseekController()
	facades.Route().Prefix("/api").Post("chat", dk_ctrl.Chat)
	//验证码
	captchaCtrl := controllers.NewCaptchaController()
	facades.Route().Get("/api/captcha", captchaCtrl.GetCaptcha)
	facades.Route().Post("/api/validate", captchaCtrl.ValidateCaptcha)

	//登录
	auth_ctrl := controllers.NewAuthController()
	facades.Route().Post("/api/login", auth_ctrl.Login)
	facades.Route().Get("/api/logout", auth_ctrl.Logout)
	facades.Route().Middleware(Jwt()).Prefix("api").Group(func(router route.Router) {

		user_ctrl := user.NewUserController()
		router.Resource("user", user_ctrl)

		//角色
		role_ctrl := system.NewRoleController()
		router.Resource("role", role_ctrl)
		router.Get("role/list", role_ctrl.List)

		router.Post("role/sync_permissions", role_ctrl.SyncPermissions)
		router.Post("user/sync_role", role_ctrl.SyncUserRoles)

		//菜单
		menu_ctrl := system.NewMenuController()
		router.Get("menu/init", menu_ctrl.Init)
		router.Get("menu/tree", menu_ctrl.Tree)
		router.Resource("menu", menu_ctrl)
		router.Get("menu/list", menu_ctrl.List)

		//菜单权限
		permission_ctrl := system.NewPermissionController()
		router.Resource("permission", permission_ctrl)
		router.Get("permission/list", permission_ctrl.List)
		//按钮权限
		btnPers_ctrl := system.NewButtonPermissionController()
		router.Get("button_permission", btnPers_ctrl.Index)
		router.Get("button_permission/list", btnPers_ctrl.List)

		//文件上传
		uploadCtrl := system.NewUploadController()
		router.Post("/upload", uploadCtrl.Upload)
		//网盘管理
		att_cate_ctrl := attachment.NewAttachmentCategoryController()
		router.Resource("attachment_category", att_cate_ctrl)
		router.Get("attachment_category/list", att_cate_ctrl.List)
		router.Get("attachment_category/{id}/attachments", att_cate_ctrl.Attachments)
		att_ctrl := attachment.NewAttachmentController()
		router.Resource("attachment", att_ctrl)
	})

}
